package org.tacticalTroopers.jme.server.object;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tacticalTroopers.jme.server.Physicer;


public class ServerGameArea {

	final static Log log = LogFactory.getLog(ServerGameArea.class);


	//Map<Integer,Clientable> clients = new HashMap<Integer,Clientable>();
	ServerGameState serverGameState = new ServerGameState(); 
	Physicer physicer;
	List<ServerElement> elements = new ArrayList<ServerElement>();

	ServerGameMap map;


	public ServerGameArea() {
		physicer = new Physicer(this);
		physicer.init();
	}
	


	/*public void init() {
		physicer.initStaticServerElements();
	}*/

	public void addDynamicElement(ServerElement elem){
		addDynamicElement(elem,0f);
	}

	public void addDynamicElement(ServerElement elem,Float initialVelocity){
		physicer.addDynamicServerElement(elem, initialVelocity);
		serverGameState.addElement(elem.getId(),elem);
		elements.add(elem);
	}

	List<ServerElement> elementsToRemove = new ArrayList<ServerElement>();
	public void removeElement(ServerElement element) {
		serverGameState.removeElement(element.getId());
		physicer.removeServerElement(element);
		elementsToRemove.add(element);
	}

	public void setMap(ServerGameMap m) {
		physicer.loadMap(m);
		map=m;
	}

	public void step(Integer milliseconds) {
		physicer.step(milliseconds);
		elementsToRemove.clear();
		for(ServerElement element : elements){
			element.step(milliseconds);
		}
		elements.removeAll(elementsToRemove);
	}

	public ServerGameState getGameState() {
		return serverGameState;
	}



	public ServerGameMap getMap() {
		return map;
	}




}
